package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import easier.log.logger.Logger;
import easier.window.picker.PickerFactory;
import easier.window.picker.PickerFragment.ActionListener;
import easier.window.picker.PickerFragment.Func;
import java.util.ArrayList;
import java.util.List;

public class MainActivity107 extends AppCompatActivity {

    private Button show;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity107.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main107 );
        initView();
    }

    private void initView() {

        show = findViewById( R.id.show );
        show.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                List< String > data = new ArrayList<>();
                for ( int i = 0; i < 20; i++ ) {
                    data.add( "item" + i );
                }
                PickerFactory.build( "请选择数据", data, new Func< String >() {
                    @Override
                    public String accept( String s ) {

                        return s;
                    }
                }, new ActionListener< String >() {
                    @Override
                    public void onCancelClick() {

                    }

                    @Override
                    public void onDoneClick( String model ) {

                        Logger.i( model );
                    }
                } ).show( getSupportFragmentManager(), "MainActivity107#PickerDialogFragment#test" );
            }
        } );
    }
}